<?php
namespace app\common\model\trends;

use think\Model;

class Cate extends Model
{
	// 设置当前模型使用的完整数据库连接信息
	protected $connection = 'database.db_second';//连接配置
    // 表名
    protected $name = 'trends_cate';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'is_name_text'
    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    
    public function getIsNameList()
    {
        return ['1' => __('Is_name 1'), '2' => __('Is_name 2')];
    }


    public function getIsNameTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_name']) ? $data['is_name'] : '');
        $list = $this->getIsNameList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
